var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        userId:''
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
        this.params.userId = Pub.getSession('userId');
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            userId:parseInt(_this.params.userId),
        };
        console.log(paramsObj);
        Api.userauthlistdetails(paramsObj, function(data){
            console.log(data);
            var data=data.data;
            $('#mobile').text(data.mobile);
            if (data.headPortrait) {
                $('#headImg').attr('src', data.headPortrait);
            };
            if (data.isVip==1) {
                $('#isVip').text('非会员');
            }
            $('#userId').text(data.userId);
            $('#gmtCreate').text(data.gmtCreate);
            $('#realName').text(data.realName);
            if (data.sex==1) {
                $('#sex').text('男');
            }else if(data.sex==2){
                $('#sex').text('女');
            }else{
                $('#sex').text('未知');
            };
            $('#real_name').text(data.realName || '~');
            $('#idNumber').text(data.idNumber || '~');
            $('#idValidity').text(data.startTerm+'~'+data.endTerm);
            if (data.idcardFront) {
                $('#idcardFront').html('<img src="'+data.idcardFront+'" >');
            };
            if (data.idcardBack) {
                $('#idcardBack').html('<img src="'+data.idcardBack+'" >');
            };
            $('#note').val(data.note);
            if (data.isAuth==0 || data.isAuth==2) {
                $('#btDiv').css('display', 'block');
            };
            if (data.isAuth==0 || data.isAuth==2) {
                $('#auditdetail').text('查看详情-待审核');
            }else if(data.isAuth==1){
                $('#auditdetail').text('查看详情-已通过');
            }else if(data.isAuth==3){
                $('#auditdetail').text('查看详情-未通过');
            };
        });
    },
    otherEvent:function(){
        var _this = this;
        $('#btDiv div').click(function(event) {
            var paramsObj = {
                passport: _this.params.passport,
                userId:_this.params.userId,
                isAuth:$(this).attr('data'),
                note:$('#note').val()
            };
            console.log(paramsObj);
            Api.userauthlistmodify(paramsObj, function(data){
                console.log(data);
                layui.use('layer', function(){
                    layer.msg('成功', {icon: 6});
                    setTimeout(function(){
                        window.location.href = Pub.getHtmlUrl('./real-name-audit.html');
                    },1500)
                });
            });
        });
    },
    initEvent: function(){
        var _this = this;
         _this.getData();
        _this.otherEvent();


    }
};
var page = new Page();